package com.iris.live.services.data.repositories.impl;

import com.iris.live.services.data.repositories.ItemTranslationRepository;
import org.springframework.stereotype.Repository;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description:
 * @author: Tony.Zhang
 * @Date: 2017-09-16 21:20
 **/
@Repository
public class ItemTranslationRepositoryImpl extends BaseRepository implements ItemTranslationRepository {
    public ItemTranslationRepositoryImpl() {
    }

    @Override
    public String getCN(String type, String item) {
        String sql = "select item_cn FROM t_item_translation_info where item_type=:itemType and item_en=:itemEn";
        Map params = new HashMap<>();
        params.put("itemType", type);
        params.put("itemEn", item);
        List<Map> resultSet = super.getList(sql, params);

        if(resultSet != null && ! resultSet.isEmpty()){
            return resultSet.get(0).get("item_cn").toString();
        }

        return item;
    }

    @Override
    public List getItems(String type) {
        String sql = "select item_cn, item_en FROM t_item_translation_info where item_type=:itemType";
        Map params = new HashMap<>();
        params.put("itemType", type);
        return super.getList(sql, params);
    }

    @Override
    public String getEN(String type, String item) {
        String sql = "select item_en FROM t_item_translation_info where item_type=:itemType and item_cn=:itemEn";
        Map params = new HashMap<>();
        params.put("itemType", type);
        params.put("itemEn", item);
        List<Map> resultSet = super.getList(sql, params);

        if(resultSet != null && ! resultSet.isEmpty()){
            return resultSet.get(0).get("item_en").toString();
        }

        return item;
    }
}
